package org.example.springtrans.controller;

import org.example.springtrans.model.LogInfo;
import org.example.springtrans.model.UserInfo;
import org.example.springtrans.service.LogInfoService;
import org.example.springtrans.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/8/3
 * Time: 01:59
 */
@RestController
@RequestMapping("/user_log")
public class UserLogController {

    @Autowired
    private UserService userService;
    @Autowired
    private LogInfoService logInfoService;

    @Transactional
    @RequestMapping("/register")
    public Boolean register(UserInfo userInfo) {
        Integer userResult = userService.register(userInfo);
        System.out.println("插入用户表,userResult:" + userResult);

        LogInfo logInfo = new LogInfo();
        logInfo.setUserName(userInfo.getUserName());
        logInfo.setOp("注册");
        Integer logResult = logInfoService.commit(logInfo);
        System.out.println("插入日志表,logResult:" + logResult);

        return true;
    }
}
